package com.maiji.cloud.controller.shopingmall;

import java.util.Date;
import java.util.List;
import com.maiji.cloud.entities.shopingmall.ShareOrderRule;
import com.maiji.cloud.entities.shopingmall.ShipmentsInfoEntity;
import com.maiji.cloud.entities.shopingmall.ShopingOrderEditLog;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.shopingmall.*;
import com.maiji.cloud.response.shopingmall.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.entities.shopingmall.ShopingAddress;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/order")
@Api(tags = {"订单模块"})
public class OrderController extends BaseController{

    /**
     *  手动发货修改
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("orderPrintUpdate")
    @ApiOperation(value = "手动发货修改")
    public BaseResDto orderPrintUpdate (@RequestBody BaseDataReqDto<OrderPrintReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/orderPrintUpdate", baseDataReqDto, BaseResDto.class);
    }

    /**
     *  手动发货
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("orderPrintManual")
    @ApiOperation(value = "手动发货")
    public BaseResDto orderPrintManual (@RequestBody BaseDataReqDto<OrderPrintReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/orderPrintManual", baseDataReqDto, BaseResDto.class);
    }

    /**
     *  打印订单发货的电子面单
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("orderPrint")
    @ApiOperation(value = "打印订单发货的电子面单")
    public BaseDataResDto<List<ShipmentsInfoEntity>> orderPrint (@RequestBody BaseDataReqDto<List<OrderPrintReqData>> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/orderPrint", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     *  打印订单发货的电子面单_增加分单
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("orderPrintAdd")
    @ApiOperation(value = "打印订单发货的电子面单_增加分单")
    public BaseDataResDto<ShipmentsInfoEntity> orderPrintAdd (@RequestBody BaseDataReqDto<OrderPrintReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/orderPrintAdd", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     *  新单号重新打印电子面单
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("orderPrintNew")
    @ApiOperation(value = "新单号重新打印电子面单")
    public BaseDataResDto<ShipmentsInfoEntity> orderPrintNew (@RequestBody BaseDataReqDto<OrderPrintReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/orderPrintNew", baseDataReqDto, BaseDataResDto.class);
    }

	  /**
     *  获取订单发货信息列表（已打印电子面单 / 代发货）
     * @param baseDataReqDto
     * @return
     */
	@PostMapping("findAllShipmentsInfos")
    @ApiOperation(value = "获取订单发货信息列表（已打印电子面单 / 代发货）")
    public BaseMetaResDto<List<List<ShipmentsInfoEntity>>> findAllShipmentsInfos (@RequestBody BaseDataReqDto<ShipmentsInfoReqData> baseDataReqDto) {
    	return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllShipmentsInfos", baseDataReqDto, BaseMetaResDto.class);
    }

	  /**
     *  订单发货
     * @param baseDataReqDto
     * @return
     */
	@PostMapping("orderSend")
    @ApiOperation(value = "订单发货")
    public BaseResDto orderSend (@RequestBody BaseDataReqDto<List<ShipmentsInfoEntity>> baseDataReqDto) {
    	return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/orderSend", baseDataReqDto, BaseResDto.class);
    }

    /**
     *  获取打印快递单代发货数量
     * @return
     */
    @PostMapping("findAllShopingOrderSendStatusCount")
    @ApiOperation(value = "获取打印快递单代发货数量")
    public BaseDataResDto<Integer> findAllShopingOrderSendStatusCount (){
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllShopingOrderSendStatusCount", null, BaseDataResDto.class);
    }

    /**
     *  获取各个状态的订单数量
     * @return
     */
    @PostMapping("findAllShopingOrderStatusCount")
    @ApiOperation(value = "获取各个状态的订单数量")
    public BaseDataResDto<List<ShopingOrderStatusCountResData>> findAllShopingOrderStatusCount (){
        return postForObjectWithToken(null,REST_URL_SHOPINGMALL + "/shopingOrder/findAllShopingOrderStatusCount", null, BaseDataResDto.class);
    }

	  /**
     *  提交单品订单/提交购物车订单
     * @param orderSubmitReqDto
     * @param token
     * @return
     */
	@PostMapping("orderSubmit")
    @ApiOperation(value = "提交单品订单/提交购物车订单")
    public BaseDataResDto<ShopingOrderResData> orderSubmitSingle (@RequestBody OrderSubmitReqDto orderSubmitReqDto,
                                                                  @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingOrder/orderSubmitSingle", orderSubmitReqDto, BaseDataResDto.class);
    }

    /**
     *  获取订单详情
     * @param findByIdReqDto
     * @return
     */
    @PostMapping("findOrderById")
    @ApiOperation(value = "获取订单详情")
    public BaseDataResDto<ShopingOrderResData> findOrderById (@RequestBody FindByIdReqDto findByIdReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingOrder/findOrderById", findByIdReqDto, BaseDataResDto.class);
        
    }

    /**
     *  取消订单
     * @param orderCancelReqDto
     * @return
     */
    @PostMapping("cancelOrderById")
    @ApiOperation(value = "取消订单")
    public BaseDataResDto<ShopingOrderResData> cancelOrderById (@RequestBody OrderCancelReqDto orderCancelReqDto,
                                                                @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingOrder/cancelOrderById", orderCancelReqDto, BaseDataResDto.class);
    }

    /**
     *  获取所有订单列表
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findAllOrders")
    @ApiOperation(value = "获取所有订单列表")
    public BaseMetaResDto<List<ShopingOrderResData>> findAllOrders (@RequestBody BaseDataReqDto<OrderFindAllReqData> baseDataReqDto){
    		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllOrders", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     *  获取所有订单列表：待发货
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findAllOrders1")
    @ApiOperation(value = "获取所有订单列表：待发货")
    public BaseMetaResDto<List<List<ShopingOrderResData>>> findAllOrders1 (@RequestBody BaseDataReqDto<OrderFindAllReqData> baseDataReqDto){
    		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllOrders1", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     *  获取用户订单列表
     * @param baseReqMetaDto
     * @param token
     * @return
     */
    @PostMapping("findUserOrdersByToken")
    @ApiOperation(value = "获取用户订单列表")
    public BaseMetaResDto<List<ShopingOrderResData>> findUserOrdersByToken_query (@RequestBody BaseDataReqDto<Integer> baseReqMetaDto,
                                                                    @RequestHeader("maijiToken") String token){
    		return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingOrder/findAllOrdersByUserId", baseReqMetaDto, BaseMetaResDto.class);
    }

    /**
     *  初始化订单数据
     * @param orderInitReqDto
     * @param token
     * @return
     */
    @PostMapping("initOrder")
    @ApiOperation(value = "初始化订单数据")
    public BaseDataResDto<ShopingOrderResData> initOrder (@RequestBody OrderInitReqDto orderInitReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingOrder/initOrder", orderInitReqDto, BaseDataResDto.class);
    }

    /**
     *  刷新订单数据
     * @param orderRefreshReqDto
     * @param token
     * @return
     */
    @PostMapping("refreshOrder")
    @ApiOperation(value = "刷新订单数据")
    public BaseDataResDto<ShopingOrderResData> refreshOrder (@RequestBody OrderRefreshReqDto orderRefreshReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingOrder/refreshOrder", orderRefreshReqDto, BaseDataResDto.class);
    }
    
    /**
     *  商品加入购物车
     * @param addToShopingCartReqDto
     * @param token
     * @return
     */
    @PostMapping("addToShopingCart")
    @ApiOperation(value = "商品加入购物车")
    public BaseResDto addToShopingCart(@RequestBody AddToShopingCartReqDto addToShopingCartReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingCart/addToShopingCart", addToShopingCartReqDto, BaseResDto.class);
    }

    /**
     *  获取购物车商品列表
     * @param baseReqMetaDto
     * @param token
     * @return
     */
    @PostMapping("findAllShopingCart")
    @ApiOperation(value = "获取购物车商品列表")
    public BaseMetaResDto<ShopingCartResData> FindAllShopingCart(@RequestBody BaseDataReqDto baseReqMetaDto,
                                                                     @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingCart/FindAllShopingCart", baseReqMetaDto, BaseMetaResDto.class);
    }

    /**
     *  批量删除购物车商品
     * @param shopingCartDelReqDto
     * @return
     */
    @PostMapping("delShopingCart")
    @ApiOperation(value = "批量删除购物车商品")
    public BaseResDto delShopingCart(@RequestBody ShopingCartDelReqDto shopingCartDelReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingCart/delShopingCart", shopingCartDelReqDto, BaseResDto.class);
    }
    
    /**
     *  添加新/修改收货地址
     * @param shopingAddressAddReqDto
     * @param token
     * @return
     */
    @PostMapping("addOrUpdateShopingAddress")
    @ApiOperation(value = "添加新/修改收货地址")
    public BaseResDto addOrUpdateShopingAddress (@RequestBody ShopingAddressAddReqDto shopingAddressAddReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingCart/addOrUpdateShopingAddress", shopingAddressAddReqDto, BaseResDto.class);
    }

    /**
     *  获取收货地址
     * @param baseReqMetaDto
     * @param token
     * @return
     */
    @PostMapping("findAllShopingAddress")
    @ApiOperation(value = "获取收货地址")
    public BaseMetaResDto<List<ShopingAddress>> findAllShopingAddress (@RequestBody BaseDataReqDto baseReqMetaDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingCart/findAllShopingAddress", baseReqMetaDto, BaseMetaResDto.class);
    }

    /**
     *  删除收货地址
     * @param findByIdReqDto
     * @return
     */
    @PostMapping("delShopingAddress")
    @ApiOperation(value = "删除收货地址")
    public BaseResDto delShopingAddress (@RequestBody FindByIdReqDto findByIdReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/shopingCart/delShopingAddress", findByIdReqDto, BaseResDto.class);
    }

    /**
     *  根据订单id获取运单编号集合
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("getTrackingNumberByOrderId")
    @ApiOperation(value = "根据订单id获取运单编号集合")
    public BaseDataResDto<List<String>> getTrackingNumberByOrderId (@RequestBody BaseDataReqDto<String> baseDataReqDto) {
    	return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/getTrackingNumberByOrderId", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     *  根据运单号获取物流轨迹
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("getLogisticsInfoByExpressNo")
    @ApiOperation(value = "根据运单号获取物流轨迹")
    public BaseDataResDto<LogisticsInfoResData> getLogisticsInfoByExpressNo (@RequestBody BaseDataReqDto<String> baseDataReqDto) {
    	return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/getLogisticsInfoByExpressNo", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 获取订单返现分享助力规则修改记录列表
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findAllShareOrderRuleLogs")
    @ApiOperation(value = "获取订单返现分享助力规则修改记录列表")
    public BaseDataResDto<List<ShareOrderRule>> findAllShareOrderRuleLogs(@RequestBody BaseDataReqDto<List<Date>> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllShareOrderRuleLogs", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 修改订单返现分享助力规则
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("updShareOrderRule")
    @ApiOperation(value = "修改订单返现分享助力规则")
    public BaseResDto updShareOrderRule(@RequestBody BaseDataReqDto<ShareOrderRule> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/updShareOrderRule", baseDataReqDto, BaseResDto.class);
    }

    /**
     * 获取订单返现分享助力规则
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findShareOrderRule")
    @ApiOperation(value = "获取订单返现分享助力规则")
    public BaseDataResDto<ShareOrderRule> findShareOrderRule(@RequestBody BaseDataReqDto<ShareOrderRule> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findShareOrderRule", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 查看订单返现活动列表
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findAllShareOrderHelpLogs")
    @ApiOperation(value = "查看订单返现活动列表：0未结算，1已结算，2全部")
    public BaseMetaResDto<List<ShareOrderLogResData>> findAllShareOrderHelpLogs(@RequestBody BaseDataReqDto<ShareOrderLogFindAllData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllShareOrderHelpLogs", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     * 查看订单返现分享助力详情
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findShareOrderHelpById")
    @ApiOperation(value = "查看订单返现分享助力详情")
    public BaseDataResDto<ShareOrderLogResData> findShareOrderHelpById(@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findShareOrderHelpById", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 编辑订单
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("editOrder")
    @ApiOperation(value = "编辑订单")
    public BaseResDto editOrder(@RequestBody BaseDataReqDto<ShopingOrderEditLogReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/editOrder", baseDataReqDto, BaseResDto.class);
    }

    /**
     * 获取订单修改记录列表
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("findAllShopingOrderEditLogs")
    @ApiOperation(value = "获取订单修改记录列表")
    public BaseMetaResDto<List<ShopingOrderEditLog>> findAllShopingOrderEditLogs(@RequestBody BaseDataReqDto<ShopingOrderEditLogReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/shopingOrder/findAllShopingOrderEditLogs", baseDataReqDto, BaseMetaResDto.class);
    }

}
